安装 PHP 5.6
- curl -s https://php-osx.liip.ch/install.sh | bash -s force 5.6
- php –ini 查看 php.ini 位置
安装memcache
- brew info memcached
- brew search memcache
- brew install memcached
libmemcached是客户端,
memcached 是服务器
- brew services start memcached
- telnet localhost 11211
PHP memcached 扩展
- http://pecl.php.net/package/memcache
- tar xzf memcache-2.2.7.tgz
- phpize
- brew list zlib
- ./configure –with-zlib-dir=/usr/local/Cellar/zlib/1.2.11
- make
- sudo make install
- extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226/memcache.so
redis
https://www.jianshu.com/p/32f2cb1bb96f
- brew install redis
- 允许接受客户端的连接 修改 usr/local/etc/redis.conf 的 daemonize no 为 daemonize yes
- sudo redis-server /usr/local/etc/redis.conf
- sudo redis-cli
- redis-cli shutdown
- ps aux | grep redis
- brew services start redis
php redis 扩展
https://github.com/phpredis/phpredis
- git clone https://github.com/phpredis/phpredis.git
- cd phpredis
- ./configure
- make
- sudo make install
- 修改 /Applications/XAMPP/xamppfiles/etc/php.ini 添加 extension=”redis.so”
brew services restart apache2
代码检测
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$memcache->set('key', '123456');
$get_value = $memcache->get('key');
echo $get_value;
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('redis','123456');
echo $redis->get('redis');
echo phpinfo();
?>